package main

import (
	"fmt"
)

func main() {
	var (
		name, passwd      string
		count, balance    int = 0, 1000
		choice, add, drop int
	)
	for {
		fmt.Println("请输入用户名和密码")
		fmt.Scan(&name, &passwd)
		count++
		if login(name, passwd) {
			fmt.Printf("请输入您的选择：\n1、存钱\n2、取钱\n3、查询余额\n4、退出\n")
			fmt.Scan(&choice)
			switch choice {
			case 1:
				fmt.Println("请输入您要存入的金额")
				fmt.Scan(&add)
				save(&balance, add)
				break
			case 2:
				fmt.Println("请输入您要取走的金额")
				fmt.Scan(&drop)
				take(&balance, drop)
				break
			case 3:
				check(balance)
				break
			case 4:
				fmt.Println("退出成功")
				break
			default:
				fmt.Println("识别失败")
				break
			}
			break
		} else {
			if count == 3 {
				fmt.Println("登录失败")
				break
			}
		}
	}
}

func login(name string, passwd string) bool {
	if name == "root" && passwd == "123456" {
		fmt.Println("登录成功")
		return true
	} else {
		fmt.Println("账号或密码错误")
		return false
	}
}

func save(balance *int, add int) {
	*balance = *balance + add
	fmt.Println("存款成功，现在的余额为", *balance)
}

func take(balance *int, drop int) {
	if drop > *balance {
		fmt.Println("余额不足")
	} else {
		*balance = *balance - drop
		fmt.Println("取款成功，现在的余额为", *balance)
	}
}

func check(balance int) {
	fmt.Println("现在的余额为", balance)
}
